﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Web.Admin.Report
{
    public partial class RWBStorageDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBind();
            }
        }
        private void DataBind()
        {


            //获取存粮信息
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT C.strName AS WBName,W.strName as TradeWBName, D.strName AS  TimeName ,E.strName AS  VarietyName,B.AccountNumber,B.strName,");
            strSql.Append("  A.StorageNumberRaw,A.Price_ShiChang,A.StorageNumberRaw*Price_ShiChang AS TotalPrice");
            strSql.Append("   FROM Dep_StorageInfo A INNER JOIN dbo.Depositor B ON A.AccountNumber=B.AccountNumber");
            strSql.Append("   INNER JOIN dbo.WB C ON B.WBID=C.ID");
            strSql.Append("   INNER JOIN dbo.WB W ON A.WBID=W.ID");
            strSql.Append("   INNER JOIN dbo.StorageTime D ON A.TimeID=D.ID");
            strSql.Append("  INNER JOIN dbo.StorageVariety E ON A.VarietyID=E.ID");
            strSql.Append("    where 1=1 and C.ISSimulate=0");

            if (Request.QueryString["TradeWBID"] != null && Request.QueryString["TradeWBID"].ToString() != "")
            {
                strSql.Append("   AND W.ID = " + Request.QueryString["TradeWBID"].ToString());
            }
            if (Request.QueryString["WBID"] != null && Request.QueryString["WBID"].ToString() != "")
            {
                strSql.Append("   AND C.ID = " + Request.QueryString["WBID"].ToString());
            }
            if (Request.QueryString["TimeID"] != null && Request.QueryString["TimeID"].ToString() != "")
            {
                strSql.Append("   AND D.ID = " + Request.QueryString["TimeID"].ToString());
            }
            if (Request.QueryString["VarietyID"] != null && Request.QueryString["VarietyID"].ToString() != "")
            {
                strSql.Append("   AND E.ID = " + Request.QueryString["VarietyID"].ToString());
            }

            if (Request.QueryString["dtBegin"] != null && Request.QueryString["dtBegin"].ToString() != "")
            {
                strSql.Append("   AND A.StorageDate> '" + Request.QueryString["dtBegin"].ToString() + "'");
                
            }
            if (Request.QueryString["dtEnd"] != null && Request.QueryString["dtEnd"].ToString() != "")
            {
                strSql.Append("   AND A.StorageDate < '" + Request.QueryString["dtEnd"].ToString() + "'");
            }


            strSql.Append("   ORDER BY A.AccountNumber,A.StorageDate");


            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            Repeater1.DataSource = dt;
            Repeater1.DataBind();



        }



        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

            DataBind();

        }

    }
}